package ui;

import model.User;

public class MainUI { // 起始界面 完成人：姜凯严 7/2
    
    public void start() {
        LoginUI loginUI = new LoginUI();
        RegisterUI registerUI = new RegisterUI();
        User user = null;
        java.util.Scanner scanner = new java.util.Scanner(System.in);
        while (true) {
            System.out.println("欢迎使用红酒销售管理系统");
            System.out.println("1. 登录");
            System.out.println("2. 注册");
            System.out.println("0. 退出");
            System.out.print("请选择: ");
            String choice = scanner.nextLine();
            if ("1".equals(choice)) {
                user = loginUI.login();
                if (user != null) break;
            } else if ("2".equals(choice)) {
                registerUI.register();
                // 注册成功后返回主菜单
            } else if ("0".equals(choice)) {
                System.out.println("已退出系统。");
                return;
            }
        }
        
        UI ui;
        if (user.getPermissionLevel() == User.PermissionLevel.admin) {
            ui = new AdminUI(user);
        } else {
            ui = new UserUI(user);
        }
        ui.show();
    }
}
